import React from 'react'
import './index.less'
import Enume from '../../enume.js'
import {filter} from 'common/index'
/**
 * 类别：组件
 * 功能：银行卡
 */
class BillDetail extends React.Component {
    constructor(props, context) {
        super(props, context);
        this.state = {
            isIncome : true,
            trans_type : "",
            time : "",
            value : "",
        }
    }
    componentWillReceiveProps (nextProps) {
        //根据消费账单组装数据
        var billList = nextProps.billList
        this.setState({
            accountStatus: nextProps.accountStatus,
            billList : billList
        });
    }

    componentWillMount() {
        var amount = this.props.billDetail.amount
        var isIncome = this.isIncome(this.props.accType,this.props.billDetail.trans_type)
        var value = isIncome ? "+ " + filter.toMoney(amount) : "- " + filter.toMoney(amount) 
        this.setState({
            isIncome : isIncome,
            trans_type : Enume.trans_type(this.props.accType,this.props.billDetail.trans_type),
            time : this.timeFilter(this.props.billDetail.acc_check_date),
            value : value
        })
    }

    timeFilter (time){
        var timeString = ""
        var timeArr = []

        var now  = new Date();
        var curYear = now.getFullYear().toString()//获取当前年份
        // if (time.length == 8) {
            if (curYear != time.substring(0,4)) {
                timeArr.push(time.substring(0,4) )
            }
            timeArr.push(time.substring(4,6) )
            timeArr.push(time.substring(6,8) )
        // }
        return timeArr.join("-")
    }
    isIncome (amount,trans_type){
        var companyAdd = ['01','04','05','06','07'] //交易类型 01：充值 02：消费03：提现 04转账 05：分账 06：退款
        var personAdd = ['01','05','06','07']
        var isIncome = false
        if ( this.props.accType=='208' && companyAdd.indexOf(trans_type)>=0 ) {
            isIncome = true
        }else if(this.props.accType=='209' && personAdd.indexOf(trans_type)>=0){
            isIncome = true
        }else{
            isIncome = false
        }
        return isIncome
    }

    render() {
        return (
        	<div className="BillDetail">
                <div className="iconItem" >
                    <div className="icon">
                    {
                        this.state.isIncome ? <img src={require('static/image/wallet-income.png')} alt="" /> : <img src={require('static/image/wallet-pay.png')} alt="" />
                    }
                        
                        
                    </div>
                </div>
                <div className="content">
                    <div>{this.state.trans_type}</div>
                    <div>{this.state.time}</div>
                </div>
                <div className="amount">
                    {this.state.value}
                </div>
        	</div>
        )
    }
}

export default BillDetail